package com.itheima.d5_resource;

import java.io.*;

public class Test2 {
    public static void main(String[] args) {
        InputStream is=null;
        OutputStream os=null;
        try {
            is=new FileInputStream("C:\\Users\\dell\\IdeaProjects\\file-io-app\\src\\img.png");
            os=new FileOutputStream("C:\\Users\\dell\\IdeaProjects\\file-io-app\\src\\img2.png");

            byte[] buffer=new byte[1024];

            int len;
            while((len=is.read(buffer))!=-1){
                os.write(buffer,0,len);
            }
            System.out.println("复制完成");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if(os!=null){
                    os.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                if(is!=null){
                    is.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
